#include <QtGui>
#include "rtagdialog.h"

RTagDialog::RTagDialog(QWidget *parent) : QDialog(parent)
{
    rTag_label = new QLabel(tr("Enter desired results tag"));
    rTag_line = new QLineEdit;
    rTag_label->setBuddy(rTag_line);
    rTag_accept = new QPushButton(tr("&Accept"));
    rTag_accept->setDefault(true);

    connect(rTag_line, SIGNAL(textChanged(QString)), this,
            SLOT(rtag_update()));
    connect(rTag_accept, SIGNAL(clicked()), this,
            SLOT(accept()));

    QVBoxLayout *mainLayout = new QVBoxLayout;
    mainLayout->addWidget(rTag_label);
    mainLayout->addWidget(rTag_line);
    mainLayout->addWidget(rTag_accept);
    setLayout(mainLayout);
    setWindowTitle(tr("Results Tag"));
    setFixedHeight(sizeHint().height());
}

void RTagDialog::rtag_update()
{
    if (this->rTag_line->text().isEmpty()) {
        this->rTag_accept->setEnabled(false);
    }
    else {
        this->rTag_accept->setEnabled(true);
    }
}

void RTagDialog::accept()
{
    QString tag = this->rTag_line->text();
    emit acceptTag(tag);
    this->close();
}

void RTagDialog::setText(QString tag)
{
    this->rTag_line->setText(tag);
}
